package org.example.managementsystem.service;

import org.example.managementsystem.model.Provider;
import org.example.managementsystem.repository.ProviderDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 供应商服务层
 */
@Service
public class ProviderService {
    private final ProviderDao providerDao;

    @Autowired
    public ProviderService(ProviderDao providerDao) {
        this.providerDao = providerDao;
    }

    /**
     * 添加供应商
     */
    /**
     * 添加供应商
     */
    public Provider addProvider(Provider provider) {
        providerDao.insertProvider(provider);
        return provider;
    }

    /**
     * 更新供应商信息
     */
    public boolean updateProvider(Provider provider) {
        return providerDao.updateProvider(provider) > 0;
    }

    /**
     * 删除供应商
     */
    public boolean deleteProvider(String providerName) {
        return providerDao.deleteProvider(providerName) > 0;
    }

    /**
     * 根据名称查询供应商
     */
    public Provider getProviderByName(String providerName) {
        return providerDao.getProviderByName(providerName);
    }

    /**
     * 查询所有供应商
     */
    public List<Provider> getAllProviders() {
        return providerDao.getAllProviders();
    }

    /**
     * 搜索供应商
     */
    public List<Provider> searchProviders(String keyword) {
        return providerDao.searchProviders(keyword);
    }

    /**
     * 按评级搜索供应商
     */
    public List<Provider> searchProvidersByRating(Integer rating) {
        return providerDao.searchProvidersByRating(rating);
    }
}
